package org.com.myfb.serviceimpl;

import java.util.Date;

import java.util.List;


import org.com.myfb.dao.PersonDaoInter;
import org.com.myfb.dao.StudentsDaoInter;
import org.com.myfb.model.Person;
import org.com.myfb.model.Students;
import org.com.myfb.model.Teachers;
import org.com.myfb.service.PersonServiceInter;
import com.opensymphony.xwork2.ActionContext;

public class PersonServiceImpl implements PersonServiceInter {

	private PersonDaoInter personDaoImpl;
	private StudentsDaoInter studentsDaoImpl;
	
	
	
	public StudentsDaoInter getStudentsDaoImpl() {
		return studentsDaoImpl;
	}



	public void setStudentsDaoImpl(StudentsDaoInter studentsDaoImpl) {
		this.studentsDaoImpl = studentsDaoImpl;
	}



	public PersonDaoInter getPersonDaoImpl() {
		return personDaoImpl;
	}



	public void setPersonDaoImpl(PersonDaoInter personDaoImpl) {
		this.personDaoImpl = personDaoImpl;
	}



	@Override
	public boolean loginService(Person person) {
		List<Person> persons = this.getPersonDaoImpl().findList(Person.class,
				" en.num = " + "'" + String.valueOf(person.getNum()) + "'" + 
		        " and en.psw = " + "'"+ String.valueOf(person.getPsw()) + "'"+ 
				" and en.power= " + "'"+String.valueOf(person.getPower()) + "'");
		if (persons.size() == 1) {
			ActionContext.getContext().getSession().put("person", persons.get(0));
			return true;
		} else {
			return false;
		}
	}



	@Override
	public boolean addTeacher(Person person, Teachers teacher, String num, String psw, int tid, String tname) {
		// TODO Auto-generated method stub
		teacher.setTid(tid);
		teacher.setTname(tname);
		person.setNum(num);
		person.setPower(1);
		person.setPsw(psw);
		person.setTeachers(teacher);
		this.getPersonDaoImpl().save(person);
		return true;
	}



	@Override
	public boolean deleteStudents(Students student) {
		// TODO Auto-generated method stub
		System.out.println("删除学生dede================c=================");
		this.getStudentsDaoImpl().delete(student);
		return true;
	}



	@Override
	public boolean addStudent(Person person,Students student, String num, String psw, int sid, String sname, String ssex, String sclass,
			Date sstarttime, int sxuezhi) {
		// TODO Auto-generated method stub
		System.out.println("================a================="+sid);
		student.setSid(sid);
		
		student.setSname(sname);
		System.out.println("================b================="+sname);
		student.setSsex(ssex);
		student.setSclass(sclass);
		System.out.println("================c================="+ssex+sclass);
		student.setSstarttime(sstarttime);
		student.setSxuezhi(sxuezhi);
		System.out.println("================d================="+sstarttime);
		person.setPower(2);
		System.out.println("================q================="+sxuezhi);
		person.setNum(num);
		person.setPsw(psw);
		System.out.println("================u================="+num+psw);
		this.getPersonDaoImpl().save(person);
		student.setPerson(person);
		this.getStudentsDaoImpl().save(student);
		System.out.println("================p=================");
		return true;
	}
	
}
